
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import common.Commands;

import ui.cli.console.Terminal;
import ui.gui.documents.EditorFactory;

public class AltaRica 
{

    /**
     * * @param args
     * @throws IOException
     */
    public static void main(String[] args) 
    {
      
    	Commands.Prepare();
    	EditorFactory.Prepare();
    	
        System.out.println("Clac Version 0.1\n");
        if (args.length == 1) 
        {
            if ((new File(args[0])).exists()) 
            {
                try
                {
                    FileInputStream script = new FileInputStream(args[0]);
                    boolean cont = Terminal.Launch(script);
                    script.close();
                    if (cont == false) {
                        return;
                    }
                }
                catch (FileNotFoundException e)
                {
                    System.out.println("Unable to open the file: " + args[0]);
                    return;
                }
                catch (IOException e) 
                {
                    System.out.println("Error: unable to close the file: " + args[0]);
                }
            }
        }
       
        Terminal.Launch();
        
    }
}
